package com.googlecode.animator.controller
{
	import com.googlecode.animator.core.AnimatorMediator;
	import com.googlecode.animator.model.ProjectSettingsProxy;
	import com.googlecode.animator.view.properties.PropertiesPanelMediator;
	import com.googlecode.animator.view.timeline.InfoPaneMediator;
	import com.googlecode.animator.view.timeline.TimelineGridMediator;
	import com.googlecode.animator.view.timeline.TransportControlsMediator;
	import com.googlecode.animator.view.topmenu.CreateButtonsMediator;
	import com.googlecode.animator.view.topmenu.TopMenuMediator;
	import com.googlecode.animator.view.viewport.MainViewportMediator;
	import com.googlecode.animator.view.viewport.ViewportMediator;
	import com.googlecode.animator.view.viewselector.ViewSelectorMediator;
	import com.googlecode.animator.view.zoom.ZoomControlMediator;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * Carries out PureMVC application startup. 
	 * @author Martin
	 */
	public class AppStartupCommand extends SimpleCommand
	{
		/**
		 * Execute the command.
		 * @param notification Body should contain a RevisedAnimator3D instance.
		 * @throws Error if incorrect body found in notification.
		 */		
		override public function execute(notification:INotification):void
		{
			var appRef:Revised3DAnimator = notification.getBody() as Revised3DAnimator;
			
			// test correct body
			if(appRef == null)
			{
				throw new Error("Notification body should contain a Revised3DAnimator instance.");
			}
			
			// register proxy instances
			registerProxies();
			
			// register mediators
			// do this after the proxies so data is available
			registerMediators(appRef);
			
			/**
		 * Register PureMVC proxy instances. 
		 */	
		}
			
		protected function registerProxies():void
		{
			facade.registerProxy(new ProjectSettingsProxy());
		}
		
		
		protected function registerMediators(appRef:Revised3DAnimator):void
		{
			// register the main app mediator
			facade.registerMediator(new AnimatorMediator(appRef));	
			
			// register the top menu mediator
			facade.registerMediator(new TopMenuMediator(appRef.topMenu));
			
			// register the create-buttons mediator
			facade.registerMediator(new CreateButtonsMediator(appRef.topMenu));
			
			// register the view selector mediators
			facade.registerMediator(new ViewSelectorMediator(appRef.view_selector_1));
			
			// register zoom control mediators
			facade.registerMediator(new ZoomControlMediator(appRef.zoom_control_1));
			facade.registerMediator(new ZoomControlMediator(appRef.zoom_control_2));
			facade.registerMediator(new ZoomControlMediator(appRef.zoom_control_3));
			facade.registerMediator(new ZoomControlMediator(appRef.zoom_control_4));
			
			// register timeline mediators
			facade.registerMediator(new TimelineGridMediator(appRef.timeline.timelineGrid));
			facade.registerMediator(new TransportControlsMediator(appRef.transportControls));
			facade.registerMediator(new InfoPaneMediator(appRef.timeline.infoPane));
				
			// register properties mediators
			facade.registerMediator(new PropertiesPanelMediator(appRef.propertiesPanel));
			
			// register viewport mediators
			facade.registerMediator(new MainViewportMediator(appRef.viewport_1));
			facade.registerMediator(new ViewportMediator(appRef.viewport_2)); 
			facade.registerMediator(new ViewportMediator(appRef.viewport_3));
			facade.registerMediator(new ViewportMediator(appRef.viewport_4));
			
			
			// facade.registerMediator(new ViewSelectorMediator(appRef.topViewportSelector));
			// facade.registerMediator(new ViewSelectorMediator(appRef.sideViewportSelector));
			
			
			
			// register materials library mediators
			//facade.registerMediator(new MaterialsLibraryMediator(appRef.materialsLibrary));
			//facade.registerMediator(new MaterialsSWFButtonMediator(appRef.loadSWF));
			//facade.registerMediator(new MaterialsFLVButtonMediator(appRef.loadFLV));
			
			
			
		}
		
	}
}